package com.liyuan.yiqixing.component.security;

import com.liyuan.yiqixing.dao.AuthenticationDao;
import com.liyuan.yiqixing.model.User;
import com.liyuan.yiqixing.service.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class SecurityUserDetailsService implements UserDetailsService {
    @Autowired
    AuthenticationDao authenticationDao;
    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        User user = authenticationDao.retrieveUserByAccount(account);
        if(user==null){
            throw new UsernameNotFoundException("用户名不存在！");
        }
        return user;
    }
}
